from models import Employee, Project, WorkExperience, Certificate, ResumeTemplate, Contract, ContractAttachment, Education
from models.base import db
from datetime import datetime

def init_db(app, db):
    with app.app_context():
        db.create_all()
        
        # 添加示例员工
        if Employee.query.count() == 0:
            employee = Employee(
                name="张三",
                gender="男",
                birth_date="1990-01-01",
                phone="13800138000",
                email="zhangsan@example.com",
                school="北京大学",
                degree="本科",
                skills="Python, Java, SQL"
            )
            db.session.add(employee)
            db.session.commit()
            
            # 添加示例合同
            contract = Contract(
                employee_id=employee.id,
                contract_number="HT2024001",
                contract_type="劳动合同",
                contract_party="公司A",
                start_date=datetime(2024, 1, 1),
                end_date=datetime(2025, 1, 1),
                is_expired=False
            )
            db.session.add(contract)
            db.session.commit()
            
            # 添加示例合同附件
            attachment = ContractAttachment(
                contract_id=contract.id,
                filename="劳动合同.pdf",
                filesize=1024,
                filetype="application/pdf",
                description="标准劳动合同",
                filepath="/uploads/contracts/1_劳动合同.pdf",
                uploader="系统"
            )
            db.session.add(attachment)
            db.session.commit()
            
            # 添加示例简历模板
            template = ResumeTemplate(
                name="标准简历模板",
                description="标准简历格式，适合大多数职位申请",
                content="{}",
                is_default=True
            )
            db.session.add(template)
            db.session.commit()

            # 添加教育背景示例数据
            edu1 = Education(
                employee_id=employee.id,
                degree="本科",
                major="计算机科学与技术",
                school="北京大学",
                graduation_date=datetime(2012, 7, 1),
                degree_type="全日制",
                is_double_certificate=True
            )
            edu2 = Education(
                employee_id=employee.id,
                degree="硕士",
                major="软件工程",
                school="清华大学",
                graduation_date=datetime(2015, 7, 1),
                degree_type="全日制",
                is_double_certificate=False
            )
            db.session.add_all([edu1, edu2])
            db.session.commit()

if __name__ == "__main__":
    from app import app, db
    init_db(app, db)
    print("Database initialized successfully!") 